﻿namespace _07.ExecuteMethodPeriodically
{
    using System;
    using System.Linq;
    using System.Threading;

    public class Timer
    {
        public Timer(TimeSpan delay, MethodDelegate invokeMethod)
        {
            this.Delay = delay;
            this.Method = invokeMethod;
            Thread thread = new Thread(() =>
            {
                while (true)
                {
                    this.Method();
                    Thread.Sleep(this.Delay);
                }
            });

            thread.Start();
        }

        public delegate void MethodDelegate();

        public TimeSpan Delay { get; set; }

        public MethodDelegate Method { get; set; }
    }
}
